package cn.edu.nuc.crm.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import cn.edu.nuc.crm.dto.PageInfo;
import cn.edu.nuc.crm.entity.Manager;
import cn.edu.nuc.crm.service.interfaces.ManagerService;
import cn.edu.nuc.crm.service.interfaces.RepaymentService;

@Controller
public class ManagerController {
	    @Autowired
		private ManagerService managerService;
	    
	    @Autowired
		private RepaymentService repaymentService;
	    
	    /**
	     * 列出经理列表
	     * @param current
	     * @param session
	     * @param model
	     * @return
	     */
	    @RequestMapping(value="/managerlist",method=RequestMethod.GET)
		public String select(@RequestParam(name="current",defaultValue="1") int current,
				HttpSession session, Model model){	
			
				List<Manager> manager = new ArrayList<Manager>();
				manager = managerService.manager();
				session.setAttribute("manager", manager);
				System.out.println(manager);
				PageInfo pi = managerService.pi(current);
				System.out.println(pi);
				session.setAttribute("pi", pi);	

				return "managerlist"; 
		}
	 @RequestMapping(value="/managerdelete",method=RequestMethod.GET)
		public String delete(Integer managerid,HttpSession session){
			int result=managerService.deleteByPrimaryKey(managerid);
			if(result>0){	
				return "/success2";	
			}else{
				session.setAttribute("info", "该经理在职，无法删除");
				return "/managerlist";
			}
		}
	 @RequestMapping(value="/managerRepayment",method=RequestMethod.GET)
		public String repaymentManage(@RequestParam(name="current",defaultValue="1") int current,
				HttpSession session, Model model){	
			try {
				PageInfo pi = repaymentService.repaymentManage(current);
				session.setAttribute("pi", pi);	
				
				return "repayment/repaymentlist";
			} catch (Exception e) {
				e.printStackTrace();
			}
			return "redirect:login";
		}
}
